package org.web2024.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.web2024.dao.Result;

@Slf4j
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(Exception.class)
    public Result allException(Exception e){
        e.printStackTrace();
        return Result.fail("服务器异常,请联系管理员");
    }

    @ExceptionHandler(BadCredentialsException.class)//捕获全局变量
    public Result BadCredentialsException(BadCredentialsException e){
        return Result.fail("用户名或密码错误");
    }

    @ExceptionHandler(NullPointerException.class)//捕获全局变量
    public Result NullPointerException(NullPointerException e){
        log.info("参数为空或参数错误");
        System.out.println(e.getMessage());
        e.printStackTrace();
        return Result.fail("参数为空或参数错误");
    }
}
